package com.exam.controller;

import com.exam.entity.FillBlanksQuestions;
import com.exam.entity.ShortAnswerQuestions;
import com.exam.entity.common.ResponseResult;
import com.exam.service.FillBlanksQService;
import com.exam.util.JsonUtils;
import com.exam.util.TimeUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;


@Controller
public class FillBlanksQController {

    @Autowired
    @Qualifier("fillBlanksQServiceImpl")
    private FillBlanksQService fillBlanksQService;
    ResponseResult responseResult=new ResponseResult();

    @RequestMapping("/add_fill_blanks_question")
    @ResponseBody
    public String add_fill_blanks_question(FillBlanksQuestions fillBlanksQuestions){
        fillBlanksQuestions.setFb_creat_time(TimeUtils.getTime());
        int i = fillBlanksQService.add_fill_blanks_question(fillBlanksQuestions);
        if (i==1){
            responseResult.setCode(200);
            responseResult.setMessage("添加成功");
        }else {
            responseResult.setCode(0);
            responseResult.setMessage("添加失败");
        }
        return JsonUtils.getJson(responseResult);
    }

    @RequestMapping("/get_fill_blanksQ_by_s_id")
    @ResponseBody
    public String get_fill_blanksQ_by_s_id(int s_id){
        List<FillBlanksQuestions> fillBlacksQBySId = fillBlanksQService.get_fill_blanksQ_by_s_id(s_id);
        responseResult.setCode(0);
        responseResult.setMessage("成功");
        responseResult.setResult(fillBlacksQBySId);
        return JsonUtils.getJson(responseResult);
    }

    @RequestMapping("/update_fill_blanksQ_by_fb_id")
    @ResponseBody
    public String update_fill_blanksQ_by_fb_id(FillBlanksQuestions fillBlanksQuestions){
        int i = fillBlanksQService.update_fill_blanksQ_by_fb_id(fillBlanksQuestions);
        if (i==1){
            responseResult.setCode(200);
            responseResult.setMessage("修改成功");
        }else {
            responseResult.setCode(0);
            responseResult.setMessage("修改失败");
        }
        return JsonUtils.getJson(responseResult);
    }

    @RequestMapping("/del_fill_blanksQ_by_fb_id")
    @ResponseBody
    public String del_fill_blanksQ_by_fb_id(int fb_id){
        int i = fillBlanksQService.del_fill_blanksQ_by_fb_id(fb_id);
        if (i==1){
            responseResult.setCode(200);
            responseResult.setMessage("删除成功");
        }else {
            responseResult.setCode(0);
            responseResult.setMessage("删除失败");
        }
        return JsonUtils.getJson(responseResult);
    }
}

